<template>
  <div class="tabs">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane 
        v-for="(childItem, index) in Tabimgs.children" 
        :key="index" 
        :label="childItem.productName"
        :name="childItem.productId"
      >
        <img 
          class="sanicon" 
          :src="fileBaseUrl() + childItem.imageUrls.split(',')[0]" 
          alt="" 
        />
        <div class="bottxt">
          <h1>{{ childItem.productName }}</h1>
          <p>{{ childItem.englishName }}</p>
          <button class="tabBtn" type="button" @click="() => gotoDetails(childItem)">查看详情</button>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script setup>
import { ref,  watch } from 'vue'
import { useRouter } from 'vue-router'
import {fileBaseUrl} from '@/apis/files'

// 定义接收的 props
const props = defineProps({
  Tabimgs: {
    type: Object,
    required: true
  }
})

const activeName = ref(props.Tabimgs?.children?.[0]?.productId || '')
const router = useRouter()

// 监听 Tabimgs 的变化
watch(() => props.Tabimgs, (newVal) => {
  if (newVal?.children?.length > 0) {
    activeName.value = newVal.children[0].productId
  }
}, { immediate: true })

// 处理标签页点击事件
const handleClick = (tab) => {
  console.log('标签页切换:', tab.name)
}

// 跳转到详情页
const gotoDetails = (childItem) => {
  router.push({
    path: '/details',
    query: {
      id: childItem.productId
    }
  })
}
</script>




<style scoped>
h1 {
  margin: 0;
  font-size: 1.3em;
}

p {
  margin: 0;
  margin-top: 5px;
  color: #3d3d3d;
  font-size: 1em;
}

.tabs {
  display: flex;
  justify-content: center;
  align-items: center;
}

.el-tabs {
  margin-top: 0px;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

:deep(.el-tabs__header) {
  margin-bottom: 30px !important;
  order: 1;
}

:deep(.el-tabs__content) {
  width: 60%;
  order: 2;
}

:deep( .el-tabs__nav-wrap::after) {
  height: 0px;
}

:deep(.el-tabs__item)  {
  font-size: 1.1em;
}

:deep( .el-tabs__item.is-active) {
  color: #000000;
  font-weight: bold;
}

:deep(.el-tabs__active-bar ) {
  background-color: #000000;
}

:deep(.el-tabs__item:hover)  {
  color: #000000;
}

.sanicon {
  width: 100%;
}

.bottxt {
  margin-top: 25px;
  margin-bottom: 25px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
 
 
.tabBtn {
  padding-top: 15px;
  padding-bottom: 15px;
  padding-left: 120px;
  padding-right: 120px;
  margin-top: 30px;
  border: 2px solid #000000;
  border-radius: 60px;
  background: none;
  font-size: .9em;
}

.tabBtn:hover {
  color: white;
  background-color: #000000;
  transition: background-color 0.5s;
}
</style>